const connection = require('../../util/rabbitmq');
class SendExchange{
    constructor(queueName,exchangeName,typeName,routingKey){
       this.queueName=queueName;
       this.routingKey=routingKey;
       this.connection=connection;
       this.channelWrapper = this.connection.createChannel({
            json: true,
            setup: channel => channel.assertExchange(exchangeName, typeName,{durable:false}),
        });
        console.log("初始化完成");
    }
    async sendMessage(msg){
        this.channelWrapper.publish(this.exchangeName,this.routingKey,msg,
            { contentType: 'application/json', persistent: true,headers: {userId: 'xudan', tenantId: '11684'} }
        ).then(()=>{
            console.log('发送成功'+global.bname);
        });
    }
    
}
module.exports=SendExchange;